package com.javaclimb.controller;

import com.javaclimb.pojo.Manager;
import com.javaclimb.service.ManagerService;
import com.javaclimb.utils.PageBean;
import com.javaclimb.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/manager")
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    /**
     * 获取全部管理员信息
     */
    @PostMapping(value = "/selectManager")
    public Result page(@RequestBody Manager sm){
        log.info("分页查询，参数：{}，{}，{}，{}，{},{}",sm.getPage(),sm.getPageSize(),sm.getId(),sm.getName(),sm.getSex(),sm.getAge());
        //调用service分页查序
        PageBean pB = managerService.page(sm.getPage(),sm.getPageSize(),sm.getId(),sm.getName(),sm.getSex(),sm.getAge());
        return Result.success(pB);
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/{ids}")//传递地址参数
    public Result delete(@PathVariable List<Integer> ids){
        log.info("批量删除操作，ids:{}",ids);
        managerService.delete(ids);
        return Result.success();
    }

    /**
     * 修改用户
     */
    @PutMapping("/updateManager")
    public Result update(@RequestBody Manager manager){
        log.info("更新管理员信息：{}",manager);
        managerService.update(manager);
        return Result.success();
    }
}
